<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
</head>
<body>
<div>
    请输入手机号：<input type="text" id="mobile" value="15316135973"/>
</div>
<div>
    请输入密码：  <input type="text" id="password" value="abc123321#"/>
</div>
<div>
    <button id="btn1">登录</button>
</div>
<div id="result">

</div>
</body>
<script type="text/javascript">
    $(document).ready(function (){
        var token;
        $("#btn1").click(function (){
            var mobile=$("#mobile").val();
            var password=$("#password").val();

            $.ajax({
                type: 'post',
                //url: 'http://dorm.zhangqx.com/login',
                url: 'http://localhost:8091/login',
                contentType: 'application/x-www-form-urlencoded',
                dataType: 'json',
                data: {
                    mobile: mobile,
                    password: password
                },
                success: function (data){
                    console.log(data)
                    if(data.status == 1){
                        alert('登录成功');
                        //$("#result").text("登录成功！")
                        token = data.data.token; //获得token
                        //对localStorage进行操作
                        console.log("localStorage success")
                        localStorage.setItem("token", token)
                        localStorage.setItem("mobile", mobile)
                        console.log(localStorage.getItem("token"))
                        console.log(localStorage.getItem("mobile"))
                        //跳转欢迎页面
                        window.location.href = "http://127.0.0.1:8091/wel"
                    }else{
                        alert('登录失败' + data.msg)
                    }
                },
                error: function (){
                    alert('参数错误')
                }
            })
        })

    })


</script>


</html>